package monsmon.util;

import java.util.*;
import monsmon.util.Util;
import java.awt.Color;

/*
 * A class holding global configuration
 *
 */
public class Config{

	private static Map<String, String> paras = new HashMap<String, String>();
	
	protected static void __add(Map<String, String> opts){
		paras.putAll(opts);
	}

	public static String gets(String key){
		return gets(key, null);
	}

	public static String gets(String key, String def){
		return Util.mgetd(paras, key, def);
	}

	public static boolean getb(String key){
		return getb(key, false);
	}

	public static boolean getb(String key, boolean def){
		String val = paras.get(key);
		boolean v = false;
		try{
			v = Boolean.parseBoolean(val);
		}catch(Exception ex){
			return def;
		}
		return v;
	}

	public static int geti(String key){
		return geti(key, -1);
	}

	public static int geti(String key, int def){
		String val = paras.get(key);
		int v = 0;
		try{
			v = Integer.parseInt(val);
		}catch(Exception ex){
			return def;
		}
		return v;
	}

	public static double getd(String key){
		return getd(key, -1);
	}

	public static double getd(String key, double def){
		String val = paras.get(key);
		double v = 0;
		try{
			v = Double.parseDouble(val);
		}catch(Exception ex){
			return def;
		}
		return v;
	}

	public static char getc(String key){
		return getc(key, '\000');
	}

	public static char getc(String key, char def){
		String val = paras.get(key);
		if(val != null && val.length() == 1){
			return val.charAt(0);
		}
		return def;
	}

	public static Color get_col(String key){
		return get_col(key, Color.WHITE);
	}

	public static Color get_col(String key, Color def){
		String val = paras.get(key);
		if(val == null) return def;
		Color v = Util.str_to_col(val);
		if(v == null) return def;
		return v;
	}

}
